﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class gameSweet : MonoBehaviour
{

    private int x;
    public int X
    {
        get
        {
            return x;
        }

        set
        {
            if (canMoved())
            {
                x = value;
            }
        }
    }
    private int y;
    public int Y
    {
        get
        {
            return y;
        }

        set
        {
            if (canMoved())
            {
                y = value;
            }
        }
    }

    public GameManager.SweetsType Type
    {
        get
        {
            return type;
        }
    }
    private GameManager.SweetsType type;
    private MovedSweet movedComponent;
    public MovedSweet MovedComponent
    {
        get
        {
            return movedComponent;
        }
    }
    private ColorSweet coloredComponent;
    public ColorSweet ColoredComponent
    {
        get
        {
            return coloredComponent;
        }
    }

    public ClearedSweet ClearedComponent
    {
        get
        {
            return clearedComponent;
        }

    }

    private ClearedSweet clearedComponent;


    [HideInInspector]
    public GameManager gameManager;

    public bool canMoved()
    {
        return MovedComponent != null;
    }
    public bool canColored()
    {
        return coloredComponent != null;
    }

    public bool canClear()
    {
        return clearedComponent != null;
    }
    void Awake()
    {
        movedComponent = GetComponent<MovedSweet>();
        coloredComponent = GetComponent<ColorSweet>();
        clearedComponent = GetComponent<ClearedSweet>();
    }

    public void Init(int x, int y, GameManager gameManager, GameManager.SweetsType type)
    {
        this.x = x;
        this.y = y;
        this.gameManager = gameManager;
        this.type = type;
    }
    //鼠标处理
    #region MyRegion

    private void OnMouseEnter()
    {
        gameManager.EnterSweet(this);
    }

    private void OnMouseDown()
    {
        gameManager.PressSweet(this);
    }

    private void OnMouseUp()
    {
        gameManager.ReleaseSweet();
    }


    #endregion//鼠标操作
}
